package com.company.controller;

import com.company.query.CompanyQuery;
import com.company.service.CompanyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.http.HttpRequest;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

@Controller
public class CompanyController {

    CompanyService companyService;
    StringRedisTemplate redisTemplate;

    public CompanyController(CompanyService companyService,StringRedisTemplate redisTemplate) {
        this.companyService = companyService;
        this.redisTemplate=redisTemplate;
    }

    @GetMapping("getAllCompany")
    @ResponseBody
    public Object getAllCompany(){
        return companyService.getAll();
    }

    @GetMapping("deleteCompany")
    public void deleteCompany(Integer key){
        companyService.deleteCompany(key);
    }

    @GetMapping("pageCompany")
    @ResponseBody
    public Object getCompbyCon(){
        CompanyQuery companyQuery = new CompanyQuery();
        companyQuery.setCompanyName("hh");
        companyQuery.setCompanyAddress("cheng");
        return companyService.getCompanyByCon(companyQuery);
    }

    @GetMapping("setRedisValue")
    public void setRedisValue(HttpServletRequest request){
        String value = request.getParameter("name");
        redisTemplate.boundValueOps("name").set(value);
    }

    @GetMapping("getRedisValue")
    @ResponseBody
    public Object getRedisValue(){
        return redisTemplate.boundValueOps("name").get();
    }

}
